package com.clock.web.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.clock.common.constant.Constants;
import com.clock.shop.domain.ShopShop;
import com.clock.shop.service.IShopShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.clock.common.core.controller.BaseController;
import com.clock.common.core.domain.AjaxResult;
import com.clock.common.core.domain.model.RegisterBody;
import com.clock.common.utils.StringUtils;
import com.clock.framework.web.service.SysRegisterService;
import com.clock.system.service.ISysConfigService;

/**
 * 注册验证
 *
 * @author ruoyi
 */
@RestController
public class SysRegisterController extends BaseController {
    @Autowired
    private SysRegisterService registerService;

    @Autowired
    private ISysConfigService configService;
    @Autowired
    private IShopShopService shopShopService;

    @PostMapping("/register")
    public AjaxResult register(@RequestBody RegisterBody user) {
        if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
            return error("当前系统没有开启注册功能！");
        }
        // if(user.getRole().equals(Constants.BOSS_ROLE_NAME)){
        //     LambdaQueryWrapper<ShopShop> queryWrapper = new LambdaQueryWrapper<>();
        //     queryWrapper.eq(ShopShop::getBossId,);
        // }

        String msg = registerService.register(user);
        return StringUtils.isEmpty(msg) ? success() : error(msg);
    }
    @PostMapping("/register/sendEmailCode")
    public AjaxResult checkRegister(@RequestBody RegisterBody user) {
        return registerService.sendEmailCode(user.getUsername(),user.getEmail());
    }
}
